package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.Set;

public interface UserDao {
    public User findByUsername(String username);
    public Set<Role> findRoleById(int id);
    public Set<Permission> findPermission(int id);

    public Page<User> selectAllByName(String queryString);

    void add(User user);

    @Insert("insert into t_user_role values (#{uid},#{rid})")
    void addUserAndRole(@Param("uid") Integer uid,@Param("rid") Integer roleId);

    void update(User user);


    @Delete("delete from t_user_role where user_id = #{id}")
    void deleteRU(Integer id);

    @Select("select count(*) from t_user_role where user_id = #{id}")
    int findById(int id);

    @Delete("delete from t_user where id =#{id}")
    void delete(int id);


    @Update("update t_user set password = #{password} where username = #{username}")
    void updatePasswordByUsername(@Param("username")String username,@Param("password") String newPassword);

    @Select("select * from t_user where username = #{user}")
    User findByUser(String username);

    void updatePasswordByUsernameOrTelephone(@Param("checkName") String checkName,@Param("encode") String encode);
}
